import { Component, OnInit } from '@angular/core';
import {Note} from '../dao/note';
import { Storage } from '@ionic/storage';
import{EventService}from'../services/event.service';

@Component({
  selector: 'app-newnote',
  templateUrl: './newnote.page.html',
  styleUrls: ['./newnote.page.scss'],
})
export class NewnotePage implements OnInit {

  public title:string="";
  public content:string="";

  constructor(private storage: Storage, public eventService: EventService ) { }

  ngOnInit() {
    console.log(this.title == "");
  }

  newNote(){
    var myDate = new Date();
    let currentTime = myDate.toLocaleString();
    
    if(this.title !="" || this.content != ""){
      let newNote = new Note(currentTime,this.title, this.content);
      this.storage.set(currentTime,newNote);
    }
  }

  // 离开页面通知首页刷新
  ionViewDidLeave(){
    this.eventService.event.emit('update');
  }

}
